﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static WinFormCenter.common.Tip;
using WinFormCenter.common;
using System.Reflection;
using static WinFormCenter.page.Gaoji;

namespace WinFormCenter.page {
    public partial class Gaoji : Form {
        public Gaoji() {
            InitializeComponent();
        }

        private void Btn_Delegate_Click(object sender, EventArgs e) {
            PageUtil.GoToNewPage(this, new FormDelegate());
        }
        private void Btn_CustomEvent_Click(object sender, EventArgs e) {
            //Tip.Info("tips事件发生了");
            Tip.Tips("123", (s, e) => Tip.Info("tips事件马上要发生了:" + e.Msg));
        }

        private void Btn_Operate_Click(object sender, EventArgs e) {
            Complex complex = new(1);
            complex += new Complex(2);
            complex = +complex;

            Console.WriteLine(complex);
        }

        private void Btn_Attribute_Click(object sender, EventArgs e) {
            
            Type type=typeof(Complex);

            foreach (var item in type.GetCustomAttributes<MyHelpAttrbute>(false)) {
                Console.WriteLine("a+++++++++++++++++++++"+ item.Name);
            }
            
            foreach (var item in type.GetMembers()) {
                foreach (var item1 in item.GetCustomAttributes<MyHelpAttrbute>()) {
                    Console.WriteLine("a+++++++++++++++++++++" + item1.Name);
                }
            }

        }
        [AttributeUsage(AttributeTargets.Class|AttributeTargets.Method,AllowMultiple =true)]
        public class MyHelpAttrbute(string name) : Attribute {
            public string Name { get; set; } = name;
        }
        /// <summary>
        /// 运算符重载
        /// </summary>
        [MyHelpAttrbute("asd"), MyHelpAttrbute("a阿萨德sd")]
        public class Complex(int age) {
            public int Age { set; get; } = age;

            /// <summary>
            /// 重载单目运算符+
            /// </summary>
            /// <param name="a"></param>
            /// <returns></returns>
            public static Complex operator +(Complex a) {
                if (a.Age < 0) {
                    a.Age = 0 - a.Age;
                }
                return a;
            }
            /// <summary>
            /// 重载双目运算符+
            /// </summary>
            /// <param name="a"></param>
            /// <returns></returns>
            public static Complex operator +(Complex? a, Complex? b) => new(a?.Age ?? 0 + b?.Age ?? 0);
            /// <summary>
            /// 重载单目运算符-
            /// </summary>
            /// <param name="a"></param>
            /// <returns></returns>
            public static Complex operator -(Complex a) {
                a.Age--;
                return a;
            }
            /// <summary>
            /// 重载单目运算符fasle if(Complex)
            /// </summary>
            /// <param name="a"></param>
            /// <returns></returns>
            public static bool operator false(Complex a) => a.Age == 0;
            /// <summary>
            /// 重载单目运算符true if(Complex)
            /// </summary>
            /// <param name="a"></param>
            /// <returns></returns>
            public static bool operator true(Complex a) => a.Age != 0;


        }

       
    }
}
